﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaskUnitProject
{
    public class TaskNote
    {
        public static void Note()
        {
            #region 1.创建Task任务的三种方式,Task任务默认是后台任务，线程池托管任务
            //1.
            Task task1 = new Task(() => { });
            task1.Start();
            //2.
            Task task2 = Task.Factory.StartNew(() => { });
            //3.
            Task task3 = Task.Run(() => { });
            #endregion

            #region 2. 线程阻塞
            //等待所有线程执行完成
            Task.WaitAll(new Task[] { task1, task2 });
            //等待任何一个线程完成
            Task.WaitAny(new Task[] { task1, task2 });
            //等待所有线程完成后执行后续操作,两种方式
            Task.WhenAll().ContinueWith(t => { });
            Task.Factory.ContinueWhenAll(new Task[] { task1, task2 }, t => { });
            //:等待任何一个线程完成后执行后续操作,两种方式
            Task.WhenAny().ContinueWith(t => { });
            Task.Factory.ContinueWhenAny(new Task[] {task1, task2}, t => { });
            #endregion

        }
    }
}
